// 状态管理的文件
import { defineStore } from "pinia";

export const useStore = new defineStore('shop', {
    persist: {
        enabled: true,//开启数据持久化
        strategies: [
          {
            key: 'shop',//给一个要保存的名称
            storage: localStorage,//sessionStorage / localStorage 存储方式
          }
        ]
    },
    //定义状态数据 - 保存本地存储数据
    state()  //data
    {
        return {
            user: {},
            addrid: 0
        }
    },
    getters: { //computed
        nickname(state)
        {
            return state.user.nickname
        }
    },
    actions: {
        edit(nickname)
        {
            this.user.nickname = nickname
        }
    }
})
